<?php

namespace App\Repositories\Eloquent\Edu;

use Illuminate\Container\Container as App;
use App\Repositories\Eloquent\Repository;

use App\Repositories\Eloquent\Edu\TermRepository as Term;
use App\Repositories\Eloquent\Mgt\UserRepository as User;

class ClaseRepository extends Repository
{

    protected $user, $term;

    public function __construct(App $app, User $user, Term $term)
    {
        parent::__construct($app);

        $this->user = $user;

        $this->term = $term;
    }

    /**
     * 指定模型名称
     *
     * @return mixed
     */
    function model()
    {
        return 'App\Models\Edu\Clase';
    }

    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {

    }


    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store($request, $termId)
    {

        $term = $this->term->find($termId);

        if (!$term) {
            return $this->responseFail(404,'培训计划信息不正确');
        }

        $result = $this->create([
            'type_id' => $term->type_id,
            'term_id' => $termId,
            'branch_id' => $term->branch_id,
            'category_id'=>$request->category,
            'name' => $request->clase,
            'number' => $request->number,
            'is_limited' => $request->is_limited,
            'is_exam' => $request->is_exam,
            'is_handin' => $request->is_handin,
            'content' => $request->content,
            'classtime' => $request->classtime,
            'memo' => $request->memo,
        ]);

        if( !!$result )
            return $this->responseSuccess('班级添加成功');

        return $this->responseFail(500, '班级科目添加失败');

    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        $clase = $this->find($id);

        if (!$clase) {
            return $this->responseFail(404);
        }

        return $clase;
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function renew($request, $id)
    {
        $result = $this->update([
            'category_id'=>$request->category,
            'name' => $request->clase,
            'number' => $request->number,
            'is_limited' => $request->is_limited,
            'is_exam' => $request->is_exam,
            'is_handin' => $request->is_handin,
            'content' => $request->content,
            'classtime' => $request->classtime,
            'memo' => $request->memo,
        ], $id);

        if(!!$result)
            return $this->responseSuccess('修改成功');

        return $this->responseFail(500,'修改失败');
    }



    public function memo($id)
    {
        $clase = $this->find($id);

        if (!$clase) {
            return $this->responseFail(404);
        }

        if(!$clase->memo)
            $clase->memo = '暂无公告';
            //return $this->responseFail(500,'暂无公告');

        return $this->responseSuccess('获取数据成功', $clase,route('wx.index'));
    }


    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //
    }


}